package com.qf.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 通过配置类向MQ中创建交换机和队列，以及绑定关系
 */
@Configuration
public class MqConfig {


    // 创建交换机
    @Bean
    public TopicExchange topicExchange(){
        return new TopicExchange("boot-ex01");
    }


    @Bean
    public DirectExchange directExchange(){
        return new DirectExchange("boot-ex02");
    }


    @Bean
    // 创建队列
    public Queue queue01(){
        return new Queue("boot-q01");
    }

    @Bean
    public Queue queue02(){
        return new Queue("boot-q02");
    }

    @Bean
    // 创建交换机和队列的绑定关系
    public Binding binding03(DirectExchange directExchange,Queue queue02){
        return BindingBuilder.bind(queue02).to(directExchange)
                .with("error");
    }



    @Bean
    public Binding binding01(TopicExchange topicExchange,Queue queue01){
        return BindingBuilder.bind(queue01).to(topicExchange)
                .with("*.red.*");
    }

    @Bean
    // 创建交换机和队列的绑定关系
    public Binding binding02(TopicExchange topicExchange,Queue queue01){
        return BindingBuilder.bind(queue01).to(topicExchange)
                .with("lazy.#");
    }


}
